#ifndef SEQIOT_PARAM_H
#define SEQIOT_PARAM_H

#include <cjson/cJSON.h>

#define PARAM_METHOD "method"
#define PARAM_TABLE "table"
#define PARAM_KEY "key"
#define PARAM_ID "id"
#define PARAM_SEGMENT "segment"
#define PARAM_TAG "tag"

#define PARAM_MAX 64

typedef struct _query_value {
    int type;
    union {
        double dbl_val;
        char *str_val;
        void *raw_val;
    };
} query_value_t;

typedef struct _query_param {
    char *key[PARAM_MAX];
    query_value_t val[PARAM_MAX];
    int size;
} query_param_t;

query_param_t *param_new();

void param_free(query_param_t *ptr);

const query_value_t *param_get_value(const query_param_t *param, const char *key);

const char *param_get_string(const query_param_t *param, const char *key);

const char *param_get_method(const query_param_t *param);

_Bool param_method_is(const query_param_t *param, const char *method);

const char *param_get_table(const query_param_t *param);

const char *param_get_key(const query_param_t *param);

const char *param_get_segment(const query_param_t *param);

const char *param_get_tag(const query_param_t *param);

int param_parse_query(query_param_t *param, const char *query);

int param_parse_cjson(query_param_t *param, const cJSON *cjson);

#endif //SEQIOT_PARAM_H